<?php
namespace app\oa\controller;
use \app\oa\controller\Role as RoleController;
use app\oa\ext\Core;
use app\oa\ext\Role;
use app\oa\model\Task;
use think\Request;

/**
 * 主任
 * Class Director
 * @package app\oa\controller
 */
class Director extends RoleController {

    protected function getRole()
    {
        return [Role::Director, Role::DeputyDirector];
    }

    public function index() {
        $tasks = Task::all(['status'=>3]);
        $this->assign("tasks", $tasks);

        $sendTasks = Task::all(['status'=>7]);
        $this->assign("sendTasks", $sendTasks);
        return $this->fetch("director/index");
    }

    public function verify($id, $pass = 1) {
        $task = Task::get($id);
        if($pass) {
            $task['status'] = 4;
        }else {
            $task['status'] = 10;
        }

        if($task->save()) {
            $this->success("操作成功");
        }
    }

    public function alterTask(Request $request, $id) {
        $core = new Core();
        $core->checkStatus($id, 3);
        $core->upload($request, $id);
    }

    public function alterSendTask(Request $request, $id) {
        $core = new Core();
        $core->checkStatus($id, 7);
        $task = Task::get($id);
        $task['status'] = 4;
        if(!$task->save()) {
            $this->error("操作失败");
        }
        $core->upload($request, $id);

    }
    public function sendTask($id) {
        $task = Task::get($id);
        $task['status'] = 8;
        if($task->save()) {
            $this->success("操作成功");
        }else {
            $this->error("操作失败");
        }
    }
}